package com.koron.standard.deviceClasssify.controller;


import com.koron.bean.base.Response;
import com.koron.standard.deviceClasssify.bean.dto.TypeGroupDTO;
import com.koron.standard.deviceClasssify.bean.po.TypeGroup;
import com.koron.standard.deviceClasssify.bean.po.TypeGroupParams;
import com.koron.standard.deviceClasssify.service.TypeGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 设备分类基本参数组(TypeGroup表)控制层
 *
 * @author jzp
 * @since 2021-07-13 11:17:29
 */
@Api(tags = "设备分类基本参数组接口")
@RestController
@RequestMapping("typeGroup")
public class TypeGroupController {

    @Autowired
    private TypeGroupService typeGroupService;

    @GetMapping("list")
    @ApiOperation(value = "查询设备分类基本参数组")
    public Response<List<TypeGroup>> selectAll() {
        List<TypeGroup> list = typeGroupService.list();
        return Response.ok(list);
    }

    @GetMapping("listDefault")
    @ApiOperation(value = "查询设备分类基本参数组预定参数")
    public Response<List<TypeGroupParams>> selectDefault() {
        List<TypeGroupParams> list = typeGroupService.listDefault();
        return Response.ok(list);
    }

    @GetMapping
    @ApiOperation(value = "查询一条设备分类基本参数组数据")
    public Response<TypeGroupDTO> selectOne(@RequestParam String id) {
        TypeGroupDTO typeGroupDTO = typeGroupService.getDtoById(id);
        return Response.ok(typeGroupDTO);
    }

    @PostMapping
    @ApiOperation(value = "新增或修改一条设备分类基本参数组数据")
    public Response insert(@RequestBody @Valid TypeGroupDTO typeGroupDTO) {
        typeGroupService.saveOrUpdateDto(typeGroupDTO);
        return Response.ok(typeGroupDTO.getId());
    }

    @DeleteMapping
    @ApiOperation(value = "删除一条设备分类基本参数组数据")
    public Response delete(@RequestParam String id) {
        typeGroupService.deleteDTO(id);
        return Response.ok();
    }

}
